package com.choudou5.spider.consts;

import org.apache.commons.lang3.StringUtils;

/**
 * @name 爬虫常量
 * @author choudou5
 * @date 2018-08-21
 */
public interface SpiderConsts {

    String HTML_BLANK = "&nbsp;";

    //----------------解析类型-------------------//
    String PARSE_HTML = "html";
    String PARSE_JSON = "json";

    enum ParamConstType{
        PAGE_NO("PAGE_NO"),
        PAGE_START("PAGE_START"),
        KEYWORD("KEYWORD"),
        RAND("RAND"),
        REPLACE("={:"),  //eg: information_id={:bottom_id}&amp;flag=down
        ;
        private String key;

        ParamConstType(String key) {
            this.key = key;
        }

        public static ParamConstType get(String key) {
            ParamConstType[] values = values();
            for (ParamConstType value : values) {
                if(value.getKey().equals(key))
                    return value;
            }
            return null;
        }

        public boolean hasKey(String url) {
            return StringUtils.contains(url, getKey());
        }

        public String getKey() {
            return key;
        }
    }


    //----------------规则类型-------------------//
    String RULE_JSOUP = "jsoup";
    String RULE_JSON = "json";
    String RULE_REGEXP = "regexp";
    String RULE_SUBSTRING = "substring";

}
